package com.ss.android.article.browser.c;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Patterns;
import android.webkit.URLUtil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class SpecialPageHelper {
    private static final Pattern a = Pattern.compile("(?i)((?:http|https|file)://|(?:inline|data|about|javascript):|(?:.*:.*@))(.*)");

    @NonNull
    public static String a(@NonNull String arg5, String arg6) {
        String v0_1;
        String v2 = arg5.trim();
        int v0 = v2.indexOf(32) != -1 ? 1 : 0;
        Matcher v3 = SpecialPageHelper.a.matcher(((CharSequence) v2));
        if (v3.matches()) {
            String v1 = v3.group(1);
            String v4 = v1.toLowerCase();
            v1 = !v4.equals(v1) ? v4 + v3.group(2) : v2;
            if (v0 != 0 && (Patterns.WEB_URL.matcher(((CharSequence) v1)).matches())) {
                v0_1 = v1.replace(" ", "%20");
                return v0_1;
            }

            v0_1 = v1;
        } else {
            if (v0 == 0 && (Patterns.WEB_URL.matcher(((CharSequence) v2)).matches())) {
                return URLUtil.guessUrl(v2);
            }

            v0_1 = URLUtil.composeSearchUrl(v2, arg6, "%s");
        }

        return v0_1;
    }

    public static boolean a(String arg5) {
        boolean v1 = true;
        String v3 = arg5.trim();
        int v0 = v3.indexOf(32) != -1 ? 1 : 0;
        if (!SpecialPageHelper.a.matcher(((CharSequence) v3)).matches() && (v0 != 0 || !Patterns.WEB_URL.matcher(((CharSequence) v3)).matches())) {
            v1 = false;
        }

        return v1;
    }

    public static boolean isSpecialUrl(@Nullable String url) {
        return url != null && url.startsWith("file://") && (url.endsWith("bookmarks.html") || url.endsWith("downloads.html") || url.endsWith("history.html") || url.endsWith("homepage.html"));
    }

    public static boolean isBookmarksUrl(@Nullable String url) {
        return url != null && url.startsWith("file://") && url.endsWith("bookmarks.html");
    }

    public static boolean isDownloadsUrl(@Nullable String url) {
        return url != null && url.startsWith("file://") && url.endsWith("downloads.html");
    }

    public static boolean isHistoryUrl(@Nullable String url) {
        return url != null && url.startsWith("file://") && url.endsWith("history.html");
    }

    public static boolean isHomePageUrl(@Nullable String url) {
        return url != null
                && url.startsWith("file://")
                && url.endsWith("homepage.html");
    }
}

